package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.FamiliesDao;
import com.itheima.pojo.Families;
import com.itheima.service.FamiliesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = FamiliesService.class)
@Transactional
public class FamiliesServiceImpl implements FamiliesService {
    @Autowired
    private FamiliesDao familiesDao;

    /**
     * @Description 根据会员id和体检人idCard
     * @Param families
     * @Return
     */
    @Override
    public Integer findByCid(Families families) {
        Integer count = familiesDao.findByCid(families);

        return count;
    }

    @Override
    public void add(Families families, Integer memID) {
        if (familiesDao.findByCid(families) == null) {
            familiesDao.add(families);
        }
        Integer famID = familiesDao.findByCid(families);
        Map<String, Integer> map = new HashMap<>();
        map.put("memID", memID);
        map.put("famID", famID);
        familiesDao.setFM(map);
    }

    /**
     * @Description 查询所有关联的
     * @Param
     * @Return
     */
    @Override
    public List<Families> findAll(Integer member_id) {
        List<Families> dataList = familiesDao.findAll(member_id);
        return dataList;
    }

    /**
     * @Description 删除体检人信息
     * @Param Families
     * @Return
     */
    @Override
    public void deleteByIdCard(Families families) {
        Integer famID = familiesDao.findByCid(families);
        familiesDao.deleteFMByFanID(famID);
        familiesDao.deleteByIdCard(families);
    }

    /**
     * @Description 查询体检人是否存在预约
     * @Param Families
     * @Return
     */
    @Override
    public long findOrderByIdCard(Families families) {
        long count = familiesDao.findOrderByIdCard(families);
        return count;
    }

    @Override
    public long fingFM(Integer member_id, Integer famID) {
        Map<String, Integer> map = new HashMap<>();
        map.put("memID", member_id);
        map.put("famID", famID);
        return familiesDao.fingFM(map);
    }
}
